﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data.OleDb;
using System.Data.SqlClient;


namespace Kwik.Orm
{
	/// <summary>
	/// Extension methods for Kwik.Orm
	/// </summary>
	public static class Extensions
	{
		/// <summary>
		/// Get the full schema by connection, the connection must have a connectionstring
		/// </summary>
		/// <param name="conn">Base connection</param>
		/// <returns>Loaded schema</returns>
		public static ISchema GetFullSchema(this DbConnection conn)
		{
			Type type = conn.GetType();
			ISchema schema = null;
			if (type.Equals(typeof(SqlConnection)))
				schema = new SqlClientSchema(conn.ConnectionString);
			else if (type.Equals(typeof(OleDbConnection)))
				schema = new OleDbSchema(conn.ConnectionString);
			else
				schema = new BaseSchema(conn.ConnectionString, "");

			schema.Load();
			return schema;
		}

	}
}
